package main

import "fmt"

//map的遍历使用for-range的结构遍历
//map的长度可以用len()
func main() {
	a := make(map[string]string)
	a["no1"] = "武汉"
	a["no2"] = "湖北"
	for k, v := range a {
		fmt.Printf("k=%v v=%v\n", k, v)
	}

	fmt.Println("a有", len(a), "对key-value") //2

	//使用for-range遍历一个结构比较复杂的map
	studentMap := make(map[string]map[string]string)
	studentMap["stu01"] = make(map[string]string, 3) //这句话不能少
	studentMap["stu01"]["name"] = "港港"
	studentMap["stu01"]["sex"] = "男"
	studentMap["stu01"]["address"] = "武汉"

	studentMap["stu02"] = make(map[string]string, 3) //这句话不能少
	studentMap["stu02"]["name"] = "猪猪"
	studentMap["stu02"]["sex"] = "女"
	studentMap["stu02"]["address"] = "武汉"
	for k1, v1 := range studentMap {
		fmt.Println("k1=", k1)
		for k2, v2 := range v1 {
			fmt.Printf("\t k2=%v v2=%v\n", k2, v2)
		}
		fmt.Println()
	}
}
